package com.power.controller;

import com.alibaba.fastjson.JSON;
import com.power.ov.ResultData;
import com.power.ov.ResultDataTable;
import com.power.service.LineService;
import com.power.service.impl.LineServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * Created with IntelliJ IDEA.
 * User: 李辽
 * Date: 2020/10/08 10:35
 * Description:更改线路启用状态同时更改所属杆塔启用状态
 * Version: V1.0
 */
@WebServlet("/modifiesLineStatus.do")
public class ModifiesLineStatusServlet extends HttpServlet{
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String state_name = request.getParameter("state_name");//获取当前行线路启用状态名称
        int  line_id = Integer.parseInt(request.getParameter("line_id"));//获取当前行线路id

        response.setContentType("application/json;charset=utf-8");
        LineService lineService = new LineServiceimpl();
        ResultDataTable resultData = new ResultDataTable();//设置响应对象
        try {
            int result = lineService.ModifiesLineStatus(state_name,line_id);
            if (result>0){
                resultData.setCode(200);
                resultData.setMessage("更改成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

        response.getWriter().write(JSON.toJSONString(resultData));
        response.getWriter().flush();
        response.getWriter().close();
    }
}























